home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / sbf3.zip / FMPROG.TXT < prev    next >
Text File  |  1992-12-02  |  22KB  |  485 lines

  1. Hello, all.  I've updated my doc file on programming the AdLib/Sound Blaster
  2. cards, and since I'm still getting requests for the original, I decided that
  3. it would save time to post it here.  Apologies to those who aren't interested.
  4.  
  5. -------------------------------------------------------------------------------
  6.  
  7.                       Programming the AdLib/Sound Blaster
  8.                                 FM Music Chips
  9.                            Version 2.0 (24 Feb 1992)
  10.  
  11.                   Copyright (c) 1991, 1992 by Jeffrey S. Lee
  12.  
  13.                                jlee@smylex.uucp
  14.  
  15.  
  16.  
  17.                         Warranty and Copyright Policy
  18.  
  19.      This document is provided on an "as-is" basis, and its author makes
  20.      no warranty or representation, express or implied, with respect to
  21.      its quality performance or fitness for a particular purpose.  In no
  22.      event will the author of this document be liable for direct, indirect,
  23.      special, incidental, or consequential damages arising out of the use
  24.      or inability to use the information contained within.  Use of this
  25.      document is at your own risk.
  26.  
  27.      This file may be used and copied freely so long as the applicable
  28.      copyright notices are retained, and no modifications are made to the
  29.      text of the document.  No money shall be charged for its distribution
  30.      beyond reasonable shipping, handling and duplication costs, nor shall
  31.      proprietary changes be made to this document so that it cannot be
  32.      distributed freely.  This document may not be included in published
  33.      material or commercial packages without the written consent of its
  34.      author.
  35.  
  36.  
  37.  
  38.                                    Overview
  39.  
  40.      Two of the most popular sound cards for the IBM-PC, the AdLib and the
  41.      Sound Blaster, suffer from a real dearth of clear documentation for 
  42.      programmers.  AdLib Inc. and Creative Labs, Inc. both sell developers'
  43.      kits for their sound cards, but these are expensive, and (in the case
  44.      of the Sound Blaster developers' kit) can be extremely cryptic.
  45.  
  46.      This document is intended to provide programmers with a FREE source
  47.      of information about the programming of these sound cards.
  48.  
  49.      The information contained in this document is a combination of 
  50.      information found in the Sound Blaster Software Developer's Kit, and
  51.      that learned by painful experience.  Some of the information may not
  52.      be valid for AdLib cards; if this is so, I apologize in advance.
  53.  
  54.      Please note that numbers will be given in hexadecimal, unless otherwise
  55.      indicated.  If a number is written out longhand (sixteen instead of 16)
  56.      it is in decimal.
  57.  
  58.  |   Changes from Version 1 of the file will be indicated by the use of change
  59.  |   bars in the left-hand margin.
  60.  
  61.  
  62.  
  63.                          Chapter One - Sound Card I/O
  64.  
  65.      The sound card is programmed by sending data to its internal registers
  66.      via its two I/O ports:
  67.  
  68.              0388 (hex) - Address/Status port  (R/W)
  69.              0389 (hex) - Data port            (W/O)
  70.  
  71.  |   The Sound Blaster Pro is capable of stereo FM music, which is accessed
  72.  |   in exactly the same manner.  Ports 0220 and 0221 (hex) are the address/
  73.  |   data ports for the left speaker, and ports 0222 and 0223 (hex) are the
  74.  |   ports for the right speaker.  Ports 0388 and 0389 (hex) will cause both
  75.  |   speakers to output sound.
  76.  
  77.      The sound card possesses an array of two hundred forty-four registers;
  78.      to write to a particular register, send the register number (01-F5) to
  79.      the address port, and the desired value to the data port.
  80.  
  81.      After writing to the register port, you must wait twelve cycles before 
  82.      sending the data; after writing the data, eighty-four cycles must elapse
  83.      before any other sound card operation may be performed.
  84.  
  85.  |   The AdLib manual gives the wait times in microseconds: three point three
  86.  |   (3.3) microseconds for the address, and twenty-three (23) microseconds
  87.  |   for the data.
  88.  |
  89.  |   The most accurate method of producing the delay is to read the register
  90.  |   port six times after writing to the register port, and read the register
  91.  |   port thirty-five times after writing to the data port.
  92.  
  93.      The sound card registers are write-only.
  94.  
  95.      The address port also functions as a sound card status byte.  To 
  96.      retrieve the sound card's status, simply read port 388.  The status 
  97.      byte has the following structure:
  98.  
  99.               7      6      5      4      3      2      1      0
  100.           +------+------+------+------+------+------+------+------+
  101.           | both | tmr  | tmr  |              unused              |
  102.           | tmrs |  1   |  2   |                                  |
  103.           +------+------+------+------+------+------+------+------+
  104.  
  105.           Bit 7 - set if either timer has expired.
  106.               6 - set if timer 1 has expired.
  107.               5 - set if timer 2 has expired.
  108.  
  109.  
  110.  
  111.                        Chapter Two - The Registers
  112.  
  113. The following table shows the function of each register in the sound 
  114. card.  Registers will be explained in detail after the table.  Registers
  115. not listed are unused.
  116.  
  117.    Address      Function
  118.    -------      ----------------------------------------------------
  119.      01         Test LSI / Enable waveform control
  120.      02         Timer 1 data
  121.      03         Timer 2 data
  122.      04         Timer control flags
  123.      08         Speech synthesis mode / Keyboard split note select
  124.    20..35       Amp Mod / Vibrato / EG type / Key Scaling / Multiple
  125.    40..55       Key scaling level / Operator output level
  126.    60..75       Attack Rate / Decay Rate
  127.    80..95       Sustain Level / Release Rate
  128.    A0..A8       Frequency (low 8 bits)
  129.    B0..B8       Key On / Octave / Frequency (high 2 bits)
  130.      BD         AM depth / Vibrato depth / Rhythm control
  131.    C0..C8       Feedback strength / Connection type
  132.    E0..F5       Wave Select
  133.  
  134. The groupings of twenty-two registers (20-35, 40-55, etc.) have an odd
  135. order due to the use of two operators for each FM voice.  The following
  136. table shows the offsets within each group of registers for each operator.
  137.  
  138.  
  139.    Channel        1   2   3   4   5   6   7   8   9
  140.    Operator 1    00  01  02  08  09  0A  10  11  12
  141.    Operator 2    03  04  05  0B  0C  0D  13  14  15
  142.  
  143. Thus, the addresses of the attack/decay bytes for channel 3 are 62 for
  144. the first operator, and 65 for the second.  (The address of the second
  145. operator is always the address of the first operator plus three).
  146.  
  147. To further illustrate the relationship, the addresses needed to control
  148. channel 5 are:
  149.  
  150.     29 - Operator 1  AM/VIB/EG/KSR/Multiplier
  151.     2C - Operator 2  AM/VIB/EG/KSR/Multiplier
  152.     49 - Operator 1  KSL/Output Level
  153.     4C - Operator 2  KSL/Output Level
  154.     69 - Operator 1  Attack/Decay
  155.     6C - Operator 2  Attack/Decay
  156.     89 - Operator 1  Sustain/Release
  157.     8C - Operator 2  Sustain/Release
  158.     A4 -             Frequency (low 8 bits)
  159.     B4 -             Key On/Octave/Frequency (high 2 bits)
  160.     C4 -             Feedback/Connection Type
  161.     E9 - Operator 1  Waveform
  162.     EC - Operator 2  Waveform
  163.  
  164.  
  165.  
  166.                        Explanations of Registers
  167.  
  168. Byte 01 - This byte is normally used to test the LSI device.  All bits
  169.           should normally be zero.  Bit 5, if enabled, allows the FM 
  170.           chips to control the waveform of each operator.
  171.  
  172.              7     6     5     4     3     2     1     0
  173.           +-----+-----+-----+-----+-----+-----+-----+-----+
  174.           |   unused  | WS  |            unused           |
  175.           +-----+-----+-----+-----+-----+-----+-----+-----+
  176.  
  177.  
  178. Byte 02 - Timer 1 Data.  If Timer 1 is enabled, the value in this 
  179.           register will be incremented until it overflows.  Upon
  180.           overflow, the sound card will signal a TIMER interrupt
  181.           (INT 08) and set bits 7 and 6 in its status byte.  The
  182.           value for this timer is incremented every eighty (80)
  183.           microseconds.
  184.  
  185.  
  186. Byte 03 - Timer 2 Data.  If Timer 2 is enabled, the value in this 
  187.